/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Documents;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author aamod
 */
public class AdmissionDocument extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
             Vector<Object> list=Documents.Query.viewAll();
             StringBuilder stb=new StringBuilder();
             out.println("<table class='table table-striped dataTable-noheader dataTable-nofooter table-bordered'><thead>");
             out.println("<th></th>");
             out.println("<th>Document Name</th>");
             out.println("<th>Document Number</th>");
             out.println("<th>Upload Document</th>");
             out.println("</thead><tbody>");
             if(!list.isEmpty())
             {
                for(int i=0;i<list.size();i++)
                {
                    DocumentsBean db=(DocumentsBean)list.get(i);
                    stb.append(db.getDocumentId()+"/");
                    out.println("<tr><td style='width:30px'><center><input type='checkbox' name='"+db.getDocumentId()+"-c' id='"+db.getDocumentId()+"-c' onclick='enableDocument(this.id)'></center></td><td><center>"+db.getDocumentName()+"</center></td>");
                    out.println("</td><td><center><input type='text' name='"+db.getDocumentId()+"-t' id='"+db.getDocumentId()+"-t' class='input-square required' style='margin: 10px;' disabled></center></td>");
                    out.println("</td><td><input type='file'  name='"+db.getDocumentId()+"-f' id='"+db.getDocumentId()+"-f' class='input-square required' style='margin: 10px;' disabled></td></tr>");
                }
             }
             out.println("</tbody></table>");
             out.println("<div class='form-actions' style='clear: both; border-bottom: 0px solid #e5e5e5;'>");
             out.println("<input type='hidden' id='docid' name='docid' value='"+stb.toString()+"'>");
             out.println("<input type='submit' class='btn btn-primary'>");
             out.println("</div>");
//             out.println("</form>");
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(AdmissionDocument.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(AdmissionDocument.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
